package com.xbongbong.pro.domain.entity;

import com.xbongbong.saas.constant.StringConstant;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.util.List;

/**
 * 用于批量更新接口
 * @author 吴峰
 * @version v1.0
 * @date 2019/3/1 19:36
 * @since v1.0
 */
@Getter
@Setter
@ToString
public class UpdateDataValueEntity implements Serializable {

    private static final long serialVersionUID = 137578264063186738L;
    /**
     * json的key
     */
    private String key;

    /**
     * es中json的key
     */
    private String esKey;

    /**
     * 值
     */
    private Object value;

    /**
     * 值的类型，用于区分数组
     */
    private String dataType;

    /**
     * 用来放子表单数据
     */
    private List<UpdateSubDataEntity> subDataList;

    public void setKey(String key){
        if (key.contains("$.")) {
            this.key = key;
        } else {

            this.key = "$."+key;
        }
    }

    public void setEsKey(String esKey){
        if (esKey.contains(StringConstant.JSON_DATA + StringConstant.POINT)) {
            this.esKey = esKey;
        } else {
            this.esKey = StringConstant.JSON_DATA + StringConstant.POINT +esKey;
        }
    }

    public UpdateDataValueEntity() {
    }

    public UpdateDataValueEntity(String key, String esKey, Object value, String dataType, List<UpdateSubDataEntity> subDataList) {
        this.key =  "$."+key;
        this.esKey = StringConstant.JSON_DATA + StringConstant.POINT +esKey;
        this.value = value;
        this.dataType = dataType;
        this.subDataList = subDataList;
    }

    public void setSubKey(String key){
        this.key = key;
    }
}
